// 引入操作数据库的方法
const db = require('../db/index')
    // var path = require("path");
var _ = require('lodash');
exports.order = (req, res) => {
    // console.log(req.query);
    // console.log(req.query);
    querys = req.query.query
    pagenum = req.query.pagenum
    pagesize = req.query.pagesize
        // console.log(querys);
        // console.log(querys);
    sql = "SELECT * FROM  sp_order ";
    db.query(sql, (err, status) => {
        if (err) return res.ResData(err)
            // console.log(status);
        if (pagenum && pagesize) {
            count = status.length //总条数 
            pagenum = parseInt(pagenum)
                // console.log(pagenum);
            pagesize = parseInt(pagesize)
                // console.log(pagesize);
                // if (querys = "'" + "%" + querys + "%" + "'" && pagenum !== 1) {
                //     pagenum = 1
                // }
            data = _.take(_.drop(status, (pagenum - 1) * pagesize), pagesize)
                // console.log(data);
            data = {
                "total": count,
                "pagenum": pagenum,
                "pagesize": pagesize,
                data
            }
            return res.ResData("获取成功", 200, { "total": count, "pagenum": pagenum, data })
        }
        res.ResData("获取成功", 200, { "total": count, "pagenum": pagenum, data })
    })
}
exports.selectorder = (req, res) => {
    const result = req.params.id
        // console.log(req.query, req.body, req.params);
    if (result == '804909574412544580') {
        res.ResData("获取物流信息成功！", 200, [{
                "time": "2018-05-10 09:39:00",
                "ftime": "2018-05-10 09:39:00",
                "context": "已签收,感谢使用顺丰,期待再次为您服务",
                "location": ""
            },
            {
                "time": "2018-05-10 08:23:00",
                "ftime": "2018-05-10 08:23:00",
                "context": "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
                "location": ""
            },
            {
                "time": "2018-05-10 07:32:00",
                "ftime": "2018-05-10 07:32:00",
                "context": "快件到达 [北京海淀育新小区营业点]",
                "location": ""
            },
            {
                "time": "2018-05-10 02:03:00",
                "ftime": "2018-05-10 02:03:00",
                "context": "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
                "location": ""
            },
            {
                "time": "2018-05-09 23:05:00",
                "ftime": "2018-05-09 23:05:00",
                "context": "快件到达 [北京顺义集散中心]",
                "location": ""
            },
            {
                "time": "2018-05-09 21:21:00",
                "ftime": "2018-05-09 21:21:00",
                "context": "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
                "location": ""
            },
            {
                "time": "2018-05-09 13:07:00",
                "ftime": "2018-05-09 13:07:00",
                "context": "顺丰速运 已收取快件",
                "location": ""
            },
            {
                "time": "2018-05-09 12:25:03",
                "ftime": "2018-05-09 12:25:03",
                "context": "卖家发货",
                "location": ""
            },
            {
                "time": "2018-05-09 12:22:24",
                "ftime": "2018-05-09 12:22:24",
                "context": "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
                "location": ""
            },
            {
                "time": "2018-05-08 21:36:04",
                "ftime": "2018-05-08 21:36:04",
                "context": "商品已经下单",
                "location": ""
            }
        ])
    }
}